using System.Runtime.InteropServices;
using System.Security;
using System.Threading.Tasks;

namespace System.Runtime.CompilerServices
{
    [StructLayout(LayoutKind.Sequential, Size = 1)]
    public struct YieldAwaitable
    {
        public YieldAwaiter GetAwaiter()
        {
            return new YieldAwaiter();
        }

        [StructLayout(LayoutKind.Sequential, Size = 1)]
        public struct YieldAwaiter : ICriticalNotifyCompletion
        {
            private static readonly Task Completed = TaskEx.FromResult(0);

            public bool IsCompleted
            {
                get { return false; }
            }

            static YieldAwaiter()
            {
            }

            public void OnCompleted(Action continuation)
            {
                Completed.GetAwaiter().OnCompleted(continuation);
            }

            [SecurityCritical]
            public void UnsafeOnCompleted(Action continuation)
            {
                Completed.GetAwaiter().UnsafeOnCompleted(continuation);
            }

            public void GetResult()
            {
            }
        }
    }
}
